const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    readidArr: [],
    scrollHeight: getApp().globalData.windowHeight,
    searchDel: false,
    recommend: '最新发布',
    typecn: '物资分类',
    typeName: '',
    addrcn: '所在地区',
    filtercn: '筛选',
    indext: 0,
    recommendList: [
      // { name: '综合推荐', id: 1 },
      // { name: '最新发布', id: 2 }
    ],
    filter: 2,
    FjLoginLog: wx.getStorageSync('FjLoginLog'),
    oftenList: wx.getStorageSync(wx.getStorageSync('FjLoginLog').UID + '') || [],//最近常看
    t: '',//发布时间筛选
    filterTime: [//发布时间筛选列表
      { name: '今天发布', id: 1 },
      { name: '一周内发布', id: 7 },
      { name: '一个月内发布', id: 30 }
    ],
    state: '',
    filterState: [//处置状态筛选列表
      { name: '处置中', id: 1 },
      { name: '已成交', id: 3 },
      { name: '已失效', id: 4 }
    ],
    gz: '',
    filterPrice: [//物资价值筛选列表
      { name: '电话或面议', id: 8, priceActive: false, index: 0 },
      { name: '1000以下', id: 8, priceActive: false, index: 1 },
      { name: '1000-3000', id: 9, priceActive: false, index: 2 },
      { name: '3000-5000', id: 10, priceActive: false, index: 3 },
      { name: '5000-10000', id: 11, priceActive: false, index: 4 },
      { name: '1万-3万', id: 12, priceActive: false, index: 5 },
      { name: '3万-5万', id: 13, priceActive: false, index: 6 },
      { name: '5万-10万', id: 14, priceActive: false, index: 7 },
      { name: '10万-15万', id: 15, priceActive: false, index: 8 },
      { name: '15万-50万', id: 3, priceActive: false, index: 9 },
      { name: '50万-100万', id: 4, priceActive: false, index: 10 },
      { name: '100万-200万', id: 5, priceActive: false, index: 11 },
      { name: '200万-500万', id: 6, priceActive: false, index: 12 },
      { name: '500万以上', id: 7, priceActive: false, index: 13 }
    ],
    tj: '',
    filterRecommend: [
      { name: '个体', id: 2, recommendActive: false, index: 0 },
      { name: '独家', id: 3, recommendActive: false, index: 1 },
      { name: '推荐', id: 1, recommendActive: false, index: 2 }
    ],
    recommendStatus: 'none',
    provName: '',
    cityName: '',
    timeStatus: 'none',
    typeStatus: 'none',
    addrStatus: 'none',
    fullStatus: 'none',
    fullStatus2: 'none',
    filterStatus: 'none',
    iconTime: ' icon-arrow-down-bold',
    iconType: ' icon-arrow-down-bold',
    iconAddr: ' icon-arrow-down-bold',
    iconRecommend: ' icon-arrow-down-bold',
    iconFilter: ' icon-shaixuan',
    zcList: [],
    ZcClassList: [],
    c: '',
    c1: '',
    c2: '',
    indexc1: '',
    indexc2: 100000,
    k: '',
    p: 0,
    p1: 0,
    p2: 0,
    indexp1: '',
    indexp2: 0,
    strPage: 15,
    ProvinceAndCity: [{
      pcid: "0",
      code: "110000",
      name: "全国"
    }],
    TempTimeS: '',
    TempTimeX: '',
    hasMore: true,
    noMore: false,
    nodataview: false,
    intCurrPage: 1,
    ADList: [],
    perShow: 10,
    noOpenLocate: false,
    mapKey: 'e24353dac4e7753f2eea4ce5e3112b2d',
    filterActive: false,
    typeRecord: {
      indexc1: '',
      indexc2: '',
      c: ''
    },
    addrRecord: {
      indexp1: '',
      indexp2: '',
      p: ''
    },
    filterRecord: {
      t: '',
      state: '',
      gz: '',
      tj: ''
    },
    scrollTopY:0,
    triggered: false,
    showBack: false, // 是否显示返回按钮
  },
  // 点击热搜词
  changeHot: function (e) {
    if (this.data.k == e.currentTarget.dataset.info) {
      this.setData({
        k: '',
        intCurrPage: 1,
        searchDel: false
      })
    }else {
      this.setData({
        k: e.currentTarget.dataset.info,
        searchDel: true,
        intCurrPage: 1
      })
      var api_input = {
        stype: "5",
        lytype: "2",
        loginuid: wx.getStorageSync('FjLoginLog').UID,
        keyword: e.currentTarget.dataset.info
      }
      // 添加卖点
      app.getDaoPost('api/FeijiuApp/Feijiu_Add_SearchRecord', api_input, function (r) {})
    }
    
    this.getZcList()
  },
  // 综合推荐
  changeRecommendActive: function (e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      recommend: this.data.recommendList[index].name,
      filter: this.data.recommendList[index].id,
      recommendStatus: 'none',
      fullStatus: 'none',
      iconRecommend: ' icon-arrow-down-bold'
    })
    this.getZcList()
  },
  searchDelF: function () {
    this.setData({
      k: '',
      searchDel: false
    })
    this.getZcList()
  },
  zcczSearch: function (e) {
    this.setData({
      k: app.trim(e.detail.value)
    })
    if (this.data.k.length > 0) {
      this.setData({
        searchDel: true
      })
    } else {
      this.setData({
        searchDel: false
      })
    }
  },
  searchBtn: function () {
    // 新增热搜词
    this.addHotData()
    this.getZcList()
  },
  bindfocus:function () {
    this.chickFull()
  },
  //选择了地区省
  pSelect1: function (e) {
    this.setData({
      p1: e.currentTarget.dataset.po,
      indexp1: e.currentTarget.dataset.io,
      p2: '',
      indexp2: '',
      p: e.currentTarget.dataset.po,
      addrcnText: this.data.ProvinceAndCity[e.currentTarget.dataset.io].name,
    })
    if (e.currentTarget.dataset.po == "00") {
      this.setData({
        p: '',
        addrcn: '所在地区'
      })
      // this.changeAddr();
      // this.getZcList()
    }
  },
  pSelect2: function (e) {
    if (e.currentTarget.dataset) {
      if (e.currentTarget.dataset.pt == "0") {
        this.setData({
          addrcnText: this.data.ProvinceAndCity[this.data.indexp1].name,
          p: this.data.p1,
          p2: e.currentTarget.dataset.pt,
          indexp2: e.currentTarget.dataset.it,
        })
        // this.changeAddr();
        // this.getZcList()
      } else {
        this.setData({
          p2: e.currentTarget.dataset.pt,
          indexp2: e.currentTarget.dataset.it,
          addrcnText: this.data.ProvinceAndCity[this.data.indexp1].list[e.currentTarget.dataset.it].name,
          p: e.currentTarget.dataset.pt
        })
        // this.changeAddr();
        // this.getZcList()
      }
    }
  },
  // 地区选择确定
  addrConfirm: function () {
    console.log('addrcnText看看这是个啥-----', this.data.addrcnText)
    this.changeAddr();
    this.getZcList();
    this.setData({
      addrcn: this.data.addrcnText.slice(0, 4),
      // 地区回显
      "addrRecord.indexp1": this.data.indexp1,
      "addrRecord.indexp2": this.data.indexp2,
      "addrRecord.p": this.data.p,
    })
  },
  // 地区重置
  addrReset: function () {
    this.setData({
      addrcnText: '所在地区',
      indexp1: '',
      indexp2: '',
      p: '',
      p1: '',
      p2: ''
    })
    // this.changeAddr();
    // this.getZcList()
  },
  //选择了c1
  cSelect1: function (e) {
    // console.log('e===', e)
    if (e.currentTarget.dataset) {
      this.setData({
        c1: e.currentTarget.dataset.co,
        indexc1: e.currentTarget.dataset.io,
        c2: '',
        indexc2: '',
        c: e.currentTarget.dataset.co,
        typeName: this.data.ZcClassList[e.currentTarget.dataset.io].GQ_classname,
      })
    }
  },
  //选择了c2
  cSelect2: function (e) {
    if (e.currentTarget.dataset) {
      if (e.currentTarget.dataset.it == 0) {
        this.setData({
          typeName: this.data.ZcClassList[this.data.indexc1].GQ_classname,
          c: this.data.c1,
          c2: e.currentTarget.dataset.ct,
          indexc2: e.currentTarget.dataset.it,
        })
      } else {
        this.setData({
          c2: e.currentTarget.dataset.ct,
          indexc2: e.currentTarget.dataset.it,
          typeName: this.data.ZcClassList[this.data.indexc1].list[e.currentTarget.dataset.it].GQ_classname,
          c: e.currentTarget.dataset.ct
        })
        // this.changeType();
        // this.getZcList()
      }
    }
  },
  // 最近常看点击
  typeTagChange: function (e) {
    this.setData({
      c1: '',
      indexc1: '',
      c2: '',
      indexc2: '',
      typeName: e.currentTarget.dataset.info.name,
      c: e.currentTarget.dataset.info.data
    })
  },
  // 物资分类确定
  typeConfirm: function () {
    this.changeType();
    this.getZcList();
    this.setData({
      "typeRecord.indexc1": this.data.indexc1,
      "typeRecord.indexc2": this.data.indexc2,
      "typeRecord.c": this.data.c,
    })
    if (this.data.FjLoginLog) {
      let res = wx.getStorageSync(wx.getStorageSync('FjLoginLog').UID + '')
      if (res) {
        res = res.filter((item) => {
          return item.name != this.data.typeName
        })
        if (this.data.c) {
          res.unshift({ name: this.data.typeName, data: this.data.c })
        }
        if (res.length > 10) {
          res.splice(10, 1)
        }
        wx.setStorageSync(wx.getStorageSync('FjLoginLog').UID + '', res)
        this.setData({
          oftenList: wx.getStorageSync(wx.getStorageSync('FjLoginLog').UID + ''),
          typecn: this.data.typeName.slice(0, 4)
        })
      } else {
        res = []
        if (this.data.c) {
          res.unshift({ name: this.data.typeName, data: this.data.c })
        }
        wx.setStorageSync(wx.getStorageSync('FjLoginLog').UID + '', res)
        this.setData({
          oftenList: wx.getStorageSync(wx.getStorageSync('FjLoginLog').UID + ''),
          typecn: this.data.typeName.slice(0, 4)
        })
      }
    }

    this.setData({
      typecn: this.data.typeName.slice(0, 4)
    })
  },
  // 物资分类重置
  typeReset: function () {
    this.setData({
      indexc1: '',
      c1: '',
      indexc2: '',
      c2: '',
      typeName: '物资分类',
      c: ''
    })
    // this.changeType();
    // this.getZcList();
  },
  // 点击综合推荐
  changeRecommend: function () {
    if (this.data.recommendStatus == 'none') {
      this.setData({
        typeStatus: 'none',
        addrStatus: 'none',
        filterStatus: 'none',
        iconType: ' icon-arrow-down-bold',
        iconAddr: ' icon-arrow-down-bold',
        recommendStatus: 'block',
        fullStatus: 'block',
        iconRecommend: ' icon-arrow-up-bold'
      })
    } else {
      this.setData({
        recommendStatus: 'none',
        fullStatus: 'none',
        iconRecommend: ' icon-arrow-down-bold'
      })
    }
  },
  //点击选择地址
  changeAddr: function () {
    if (this.data.addrStatus == 'none') {
      this.setData({
        typeStatus: 'none',
        recommendStatus: 'none',
        filterStatus: 'none',
        iconTime: ' icon-arrow-down-bold',
        iconType: ' icon-arrow-down-bold',
        iconRecommend: ' icon-arrow-down-bold',
        addrStatus: 'block',
        fullStatus: 'block',
        iconAddr: ' icon-arrow-up-bold'
      })
    } else {
      this.setData({
        addrStatus: 'none',
        fullStatus: 'none',
        iconAddr: ' icon-arrow-down-bold'
      })
    }
  },
  //点击物资分类
  changeType: function () {
    if (this.data.typeStatus == 'none') {
      this.setData({
        addrStatus: 'none',
        recommendStatus: 'none',
        filterStatus: 'none',
        iconAddr: ' icon-arrow-down-bold',
        iconTime: ' icon-arrow-down-bold',
        iconRecommend: ' icon-arrow-down-bold',
        typeStatus: 'block',
        fullStatus: 'block',
        iconType: ' icon-arrow-up-bold'
      })
    } else {
      this.setData({
        typeStatus: 'none',
        fullStatus: 'none',
        iconType: ' icon-arrow-down-bold'
      })
    }
  },
  // 点击筛选
  changeFilter: function () {
    if (this.data.filterStatus == 'none') {
      this.setData({
        typeStatus: 'none',
        addrStatus: 'none',
        recommendStatus: 'none',
        iconType: ' icon-arrow-down-bold',
        iconAddr: ' icon-arrow-down-bold',
        iconRecommend: ' icon-arrow-down-bold',
        filterStatus: 'block',
        fullStatus: 'none',
        fullStatus2: 'block',
      })
    } else {
      this.setData({
        filterStatus: 'none',
        fullStatus2: 'none',
        iconType: ' icon-arrow-down-bold'
      })
    }
  },
  // 选择发布时间
  chooseTime: function (e) {
    if (this.data.t == e.currentTarget.dataset.info.id) {
      this.setData({
        t: '',
      })
    } else {
      this.setData({
        t: e.currentTarget.dataset.info.id,
      })
    }

  },
  // 选择处置状态
  chooseState: function (e) {
    if (this.data.state == e.currentTarget.dataset.info.id) {
      this.setData({
        state: ""
      })
    } else {
      this.setData({
        state: e.currentTarget.dataset.info.id
      })
    }
  },
  // 选择物资价值
  choosePrice: function (e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      ["filterPrice[" + index + "].priceActive"]: !this.data.filterPrice[index].priceActive
    })
    var ids = this.data.filterPrice.map(item => {
      if (item.priceActive) {
        return item.id
      }
    }).filter(i => i)
    this.setData({
      gz: ids.join()
    })
  },
  // 选择推荐属性
  chooseRecommend: function (e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      ["filterRecommend[" + index + "].recommendActive"]: !this.data.filterRecommend[index].recommendActive
    })
    var ids = this.data.filterRecommend.map(item => {
      if (item.recommendActive) {
        return item.id
      }
    }).filter(i => i)
    this.setData({
      tj: ids.join()
    })
  },
  // 筛选确定
  filterConfirm: function () {
    this.changeFilter();
    this.getZcList();
    if (this.data.t !== '' || this.data.state !== '' || this.data.gz !== '' || this.data.tj !== '') {
      this.setData({
        filterActive: true
      })
    } else {
      this.setData({
        filterActive: false
      })
    }
    // 筛选回显
    this.setData({
      "filterRecord.t": this.data.t,
      "filterRecord.state": this.data.state,
      "filterRecord.gz": this.data.gz,
      "filterRecord.tj": this.data.tj,
    })
  },
  // 筛选重置
  filterReset: function () {
    this.setData({
      t: '',
      state: '',
      gz: '',
      tj: ''
    })
    var filterPrice = this.data.filterPrice.map(item => {
      return { ...item, priceActive: false }
    })
    var filterRecommend = this.data.filterRecommend.map(item => {
      return { ...item, recommendActive: false }
    })
    this.setData({
      filterPrice: filterPrice,
      filterRecommend: filterRecommend,
    })
    // this.changeFilter();
    // this.getZcList();
  },
  // 点击遮罩层
  chickFull: function () {
    this.setData({
      timeStatus: 'none',
      typeStatus: 'none',
      addrStatus: 'none',
      recommendStatus: 'none',
      filterStatus: 'none',
      fullStatus: 'none',
      fullStatus2: 'none',
      iconTime: ' icon-arrow-down-bold',
      iconType: ' icon-arrow-down-bold',
      iconAddr: ' icon-arrow-down-bold',
      iconRecommend: ' icon-arrow-down-bold',
      // 物资分类回显
      indexc1: this.data.typeRecord.indexc1,
      indexc2: this.data.typeRecord.indexc2,
      c: this.data.typeRecord.c,
      // 地区回显
      indexp1: this.data.addrRecord.indexp1,
      indexp2: this.data.addrRecord.indexp2,
      p: this.data.addrRecord.p,
      // 筛选回显
      t: this.data.filterRecord.t,
      state: this.data.filterRecord.state,
      gz: this.data.filterRecord.gz,
      tj: this.data.filterRecord.tj,
    })

    // 筛选--物资价值回显
    var gzArr = this.data.filterRecord.gz.split(',')
    var newFilterPrice = this.data.filterPrice.map(item => {
      const priceActive = gzArr.some(i => i == item.id);
      return { ...item, priceActive: priceActive };
    });
    this.setData({
      filterPrice: newFilterPrice
    })

    // 筛选--推荐属性回显
    var tjArr = this.data.filterRecord.tj.split(',')
    var newFilterRecommend = this.data.filterRecommend.map(item => {
      const recommendActive = tjArr.some(i => i == item.id);
      return { ...item, recommendActive: recommendActive };
    });
    this.setData({
      filterRecommend: newFilterRecommend
    })

  },
  // 点击当前位置
  chooseLocate: function () {
    this.data.ProvinceAndCity.forEach((item, index) => {
      if (this.data.provName.indexOf(item.name) !== -1) {
        this.setData({
          indexp1: index,
          p1: '0' + item.pcid,
        })
      }
    })
    this.data.ProvinceAndCity[this.data.indexp1].list.forEach((item, index) => {
      if (this.data.cityName == item.name) {
        this.setData({
          addrcn: item.name.slice(0, 4),
          addrcnText: item.name.slice(0, 4),
          indexp2: index,
          p1: item.pcid,
          p: item.pcid
        })
      }
    })
    // console.log(this.data.p)
  },
  // 定位
  getAddr: function () {
    var that = this
    wx.getSetting({
      success(res) {
        // 如果已拒绝授权，则打开设置页面
        if (res.authSetting['scope.userLocation'] == false) {
          that.setData({
            noOpenLocate: true
          })
          wx.openSetting({
            success(res) {
              console.log('settingres==', res)
              // 如果授权位置, 重新获取当前位置
              if (res.authSetting['scope.userLocation'] == true) {
                that.setData({
                  noOpenLocate: false
                })
                that.getMyLocation()
              } else {
                wx.showToast({
                  title: '授权失败',
                  icon: 'error'
                })
              }

            }
          })
        } else {
          that.getMyLocation()
        }
      }
    })

  },
  getMyLocation: function () {
    var that = this;
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        that.getweizhi(latitude, longitude)
      }
    })
  },
  // 获取位置
  getweizhi: function (latitude, longitude) {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
        wx.request({
      url: `https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=${longitude},${latitude}&key=e24353dac4e7753f2eea4ce5e3112b2d`,
      header: {
        'Content-Type': 'application/json'
      },
      success: function (result) {
        wx.hideLoading()
        that.setData({
          provName: result.data.regeocode.addressComponent.province,
          cityName: result.data.regeocode.addressComponent.city
        })
      },
      fail: function (res) {
        // that.getFJ_Get_RecListKey();
      }
    })
    // wx.request({
    //   url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${that.data.mapKey}`,
    //   header: {
    //     'Content-Type': 'application/json'
    //   },
    //   success: function (result) {
    //     wx.hideLoading()
    //     console.log('result==', result)
    //     that.setData({
    //       provName: result.data.result.ad_info.province,
    //       cityName: result.data.result.ad_info.city
    //     })
    //   },
    //   fail: function (res) {
    //     // that.getFJ_Get_RecListKey();
    //   }
    // })
  },
  // 重新定位
  againLocation: function () {
    this.getAddr()
  },

  // 新增热搜词
  addHotData: function () {
    var that = this
    var api_input = {
      stype: "5",
      lytype: "2",
      loginuid: wx.getStorageSync('FjLoginLog').UID,
      keyword: this.data.k
    }
    app.getDaoPost('api/FeijiuApp/Feijiu_Add_SearchRecord', api_input, function (r) {
      if (r.code == 200) {
        that.getHotData()
      } else {
      }
    })
  },

  // 获取热搜词
  getHotData: function () {
    var that = this
    var api_input = {
      loginuid: wx.getStorageSync('FjLoginLog').UID,
      platform_type: 4,
    }
    app.getDaoPost('api/FeijiuApp/Feijiu_GetZCKeyList_v2024', api_input, function (r) {
      if (r.code == 200) {
        that.setData({
          hotDataList: r.data
        })
      } else {
      }
    })

    // var that = this;
    // wx.request({
    //   url: app.data.api_url + "api/FeijiuApp/Feijiu_GetZCKeyList_v2024",
    //   method: 'POST',
    //   // header: {
    //   //   'Content-Type': 'application/x-www-form-urlencoded',
    //   // },
    //   data: {
    //     loginuid: that.data.FjLoginLog.UID
    //   },
    //   success: function (res) {
    //     console.log('res==', res)

    //     if (res.statusCode == 200) {
    //       // that.setData({
    //       //   
    //       // })
    //     }

    //   }
    // })
  },

  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var value = wx.getStorageSync('zcReadDataID');
    if (value.length) {
      this.setData({
        readidArr: value
      })
    }
    if (options) {
      if (options.name === '废旧金属') {
        this.setData({
          indexc1: 1,
          indexc2: '',
          typeName: '废金属',
          c: options.classId,
          typecn: '废金属',
          "typeRecord.indexc1": 1,
          "typeRecord.indexc2": '',
          "typeRecord.c": options.classId,
        })
      }
      if (options.name === '二手设备') {
        this.setData({
          indexc1: 3,
          indexc2: '',
          typeName: options.name,
          c: options.classId,
          typecn: options.name,
          "typeRecord.indexc1": 3,
          "typeRecord.indexc2": '',
          "typeRecord.c": options.classId,
        })
      }
    }
    if (options.key) {
      this.setData({
        k: options.key,
        searchDel: true,
      })
    }
 // 从详情页更多分类过来-判断分类
 if (options.className) {
  this.setData({
    typecn: options.className,
    c: options.classID,
  })
}
    var that = this;
    var api_input = {
      AppType: '小程序'
    }
    app.getDaoPost('api/FeijiuApp/Post_FJ_ZcClassList', api_input, function (r) {
      if (r.code == 200) {
        var zcList2 = r.data;
        var words = that.data.ZcClassList.concat(zcList2);
        
        that.setData({
          ZcClassList: words
        })

        if (options.className) {
          // 如果是从详情页点击更多过来的数据，要遍历indexc1获取分类数组的index,然后选中当前的分类
          // 当前的分类是否选中是通过index确定的
          that.data.ZcClassList.forEach((item, index) => {
            if (that.data.typecn.indexOf(item.GQ_classname) !== -1) {
              that.setData({
                indexc1: index,
              })
            }
          })
        }
        
      }
    })
    wx.request({
      url: app.data.api_url + "api/FeijiuApp/GetCProvinceAndCity?strRSA=" + app.data.strRSA,
      success: function (res) {
        if (res.statusCode == 200) {
          var addr1 = res.data.data
          var addr2 = [{
            pcid: "0",
            code: "110000",
            name: "城市不限"
          }]
          for (var i = 0; i < addr1.length; i++) {
            addr1[i].list.unshift(addr2[0])
          }
          var addr3 = that.data.ProvinceAndCity.concat(addr1);
          that.setData({
            ProvinceAndCity: addr3
          })
        }

      }
    })
   

    // 获取当前位置
    this.getAddr()
    // 获取热搜词
    this.getHotData()
    // 最近常看
    if (this.data.FjLoginLog.UID) {
      this.setData({
        oftenList: wx.getStorageSync(wx.getStorageSync('FjLoginLog').UID + '') || []
      })
    }

    

    this.Post_FJ_GetZCList_Page();
    this.getZongHeData()

  },
  getZongHeData() {
    let api_input = {
      infotype: 1 // 1资产  2拍卖
    }
    var that = this
    app.getDaoPost('api/FeijiuApp/Feijiu_Get_Filter_v2024', api_input, function (r) {
      if (r.code == 200) {
        that.setData({
          recommendList: r.data
        })
      }
    })
  },


  zcpic: function (arr) {
    var phonelist = [];
    if (arr == '') {
      phonelist = [''];
    } else {
      phonelist = arr.split("|");
    }
    return phonelist[0];
  },

  dateTimeChang: function (d) {
    d = d.replace(/-/g, '/');
    return d
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('UID==', this.data.FjLoginLog.UID)
    this.setData({
      FjLoginLog: wx.getStorageSync('FjLoginLog'),
      oftenList: wx.getStorageSync(wx.getStorageSync('FjLoginLog').UID + '') || []
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // this.setData({
    //   zcList: [],
    //   intCurrPage: 1
    // })
    // this.Post_FJ_GetZCList_Page();
    // wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.noMore) {
      this.Post_FJ_GetZCList_Page();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    var shareObj = {
      title: 'Feijiu网资产处置',
      path: '/pages/zichanchuzhi/index',
      imgUrl: '',
    }
    return shareObj;
  },

  Post_FJ_GetZCList_Page: function () {
    var that = this;
    let loginUID = ''
    if (app.checkFjLogin()) { //token先看是不是登录了
      loginUID = this.data.FjLoginLog.UID
    }
    var api_input = {
      filter: this.data.filter,
      cindex: this.data.c,
      p: this.data.p,
      t: this.data.t,
      state: this.data.state,
      gz: this.data.gz,
      tj: this.data.tj,
      k: this.data.k,
      showTj: false,
      showGt: false,
      showDj: false,
      intCurrPage: this.data.intCurrPage,
      AppType: '小程序',
      loginuid: loginUID
    }
    function extractTextFromHTML(htmlString) {
      var text = htmlString.title.replace(/<[^>]+>/g, '');
      text = text.trim()
      // 推荐，个体，独家标签
      // tjid>0  是推荐, 标题里包含(独家)是独家, 标题里包含(个体)是个体
      if (htmlString.tjid > 0) {
        return `<img src="https://style.feijiu.net/images/app/tjIcon.png" style="width: 38px;vertical-align: sub;margin-right:5px"/>` + htmlString.title
      }
      if (text.indexOf('独家') !== -1) {
        return `<img src="https://style.feijiu.net/images/app/djIcon.png" style="width: 38px;vertical-align: sub;margin-right:5px"/>` + htmlString.title
      }
      if (text.indexOf('个体') !== -1) {
        return `<img src="https://style.feijiu.net/images/app/gtIcon.png" style="width: 38px;vertical-align: sub;margin-right:5px"/>` + htmlString.title
      }
      return htmlString.title
      // 使用正则表达式去除HTML标签  
      // var text = htmlString.replace(/<[^>]+>/g, '');
      // return text.trim(); // 去除首尾的空白字符  
    }
    wx.showLoading({
      title: '加载中...',
    })
    app.getDaoPost('api/FeijiuApp/Feijiu_GetZCList_Page_v2024', api_input, function (r) {
      wx.hideLoading()
      if (r.code == 200) {
        if (that.data.intCurrPage == 1) {
          that.setData({
            zcList: [],
          })
        }
        if (r.data.ds.length > 0) {
          var list1 = r.data.ds;
          for (var i = 0; i < list1.length; i++) {
            list1[i].fbdate = list1[i].fbdate.replace('T', " ")
            list1[i].pic = that.zcpic(list1[i].photo);
            const highlightedResult = list1[i].title.replace(new RegExp(that.data.k, 'gi'), '<span style="color: red;">$&</span>');
            list1[i].title = highlightedResult;
            if (that.data.readidArr.indexOf(list1[i].id) == -1) {
              list1[i].read = false;
            } else {
              list1[i].read = true;
            }
            if (list1[i].keywords != '') {
              let arr = list1[i].keywords.split(',')
              let filteredArr = arr.filter(item => item !== "");  
              list1[i].keywords = filteredArr
            }
            list1[i].title = extractTextFromHTML(list1[i]);
          }
          var words = that.data.zcList.concat(list1);
          that.setData({
            zcList: words,
            ADList: r.data.ADList,
            intCurrPage: that.data.intCurrPage + 1
          })
          if (list1.length < 10) {
            that.setData({
              hasMore: false,
              noMore: true,
              nodataview: false,
            })
          } else {
            that.setData({
              hasMore: true,
              noMore: false,
              nodataview: false,
            })
          }
        } else {
          that.setData({
            hasMore: false,
            noMore: true,
            nodataview: true,
          })
        }
      }
    })
  },
  preventTouchMove: function () {
  },
  navClick: function (e) {
    var itemdata = e.currentTarget.dataset.itemdata;
    var index = e.currentTarget.dataset.index;
    var gqid = itemdata.id;
    if (this.data.readidArr.indexOf(gqid) == -1) {
      this.data.readidArr.push(gqid);
      wx.setStorageSync('zcReadDataID', this.data.readidArr);
    }
    itemdata.read = true;
    this.data.zcList.splice(index, 1, itemdata);
    this.setData({
      zcList: this.data.zcList
    })
  },
  getZcList: function () {
    this.setData({
      // zcList: [],
      intCurrPage: 1
    })
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 10
    })
    this.Post_FJ_GetZCList_Page();
  },
 
  toshanpu: function (e) {
    var uid = e.currentTarget.dataset.uid;
    var adclass = e.currentTarget.dataset.adclass;
    let item = e.currentTarget.dataset.item
    let url = item.htmlurl
   
    let loginuid = wx.getStorageSync('FjLoginLog').UID
    let parame = {
      lytype: 3,
      aid: item.Aid,
      loginuid: loginuid ? loginuid : "0"
    }
    this.maiDianData(parame) 
    // if (item.uid != 0) {
    //   wx.navigateTo({
    //     url: '../gongqiuxinxi/shangpu?longUID=' + e.currentTarget.dataset.uid
    //   })
    // } else {

    // }
    if (adclass == 6 || uid == 0) {
    } else {
      wx.navigateTo({
        url: '../gongqiuxinxi/shangpu?longUID=' + uid
      })
    }

  },
   // 点击添加广告的
   maiDianData(parame) {
    app.getDaoPost('api/FeijiuApp/Feijiu_AddADHit_v2024', parame, r => {
    })
  },
  //图片加载失败时
  errorFunction: function (event) {
    var index = event.currentTarget.dataset.index
    var img = 'zcList[' + index + '].pic'
    this.setData({
      [img]: '/images/placeholderimg.png'
    })
  },
  // 点击返回顶部
  backTopClick: function() {
    // wx.pageScrollTo({
    //   scrollTop:0,
    //   duration:100
    // })
    this.setData({
      scrollTopY: 0
    })
  },
  // 加载更多
  bindscrolltolowersss: function (event) {
    if (!this.data.noMore) {
      this.Post_FJ_GetZCList_Page();
    }
  },
  // 下拉刷新
  bindrefresherrefresh(e) {
    this.setData({
      triggered: true
    })
    this.setData({
      intCurrPage: 1
    })
    this.Post_FJ_GetZCList_Page();
    setTimeout(() => {
      this.setData({
        triggered: false
      })
    }, 2000);
  },
  // 滑动的时候调用
  binddraggings(e) {
    if (e.detail.scrollTop >= 1000) {
      this.setData({
        showBack: true
      })
    }else {
      this.setData({
        showBack: false
      })
    }
  },
    // 滚动到顶部
    bindscrolltoupper(e) {
      this.setData({
        showBack: false
      })
    }
  
 
})